package com.generator.marketManage.orderManage.service.impl;

import com.generator.marketManage.orderManage.dao.OrderManageMap;
import com.generator.marketManage.orderManage.pojo.*;
import com.generator.marketManage.orderManage.service.IOrderManageService;
import com.generator.util.PageModel;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class OrderManageService implements IOrderManageService {

    @Autowired
    private OrderManageMap orderManageMap;

    public OrderManageMap getOrderManageMap() {
        return orderManageMap;
    }

    public void setOrderManageMap(OrderManageMap orderManageMap) {
        this.orderManageMap = orderManageMap;
    }

    @Override
//    分页查询订单信息
    public PageModel<Order> queryOrder(OrderCondition condition, PageModel<Order> pageModel) {
        pageModel.setPageSize(4);
        pageModel.setPageNum(pageModel.getPageNum()<=0?1:pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize()<=0?3:pageModel.getPageSize());

        Page<Object> pageinfo = PageHelper.startPage(pageModel.getPageNum(), pageModel.getPageSize());

        List<Order> list = orderManageMap.queryOrder(condition);

        PageInfo<Order> warehousePageInfo = new PageInfo<Order>(list);

        pageModel.setData(new ArrayList<Order>(list));
        pageModel.setTotalPage(warehousePageInfo.getPages());
        pageModel.setTotalRows(warehousePageInfo.getTotal());

        return pageModel;
    }

    @Override
    //订单编号拿订单信息
    public List<Order> queryOrderById(OrderCondition orderCondition) {
        return orderManageMap.queryOrder(orderCondition);
    }

    @Override
    //订单号那订单明细
    public List<OrderDetail> queryOrderDetailById(OrderDetail orderDetail) {
        return orderManageMap.queryOrderDetailById(orderDetail);
    }

    @Override
    //根据订单号删除订单
    public Integer deleteOrder(OrderCondition condition) {
        String orderid = condition.getOrderid();
        if (orderid!=""&&orderid!=null){
            condition.setOrderid(orderid);
            return orderManageMap.deleteOrder(condition);
        }
        return null;
    }

    @Override
    //根据部门查询职位
    public List<Job> queryJobByDept(Job job) {
        return orderManageMap.queryJobByDept(job);
    }

    @Override
    //根据职位查姓名
    public List<Job> queryNameByJob(Job job) {
        return orderManageMap.queryNameByJob(job);
    }

    //提交审核
    public Integer suubCheck(Order order){
        return orderManageMap.subCheck(order);
    }

    //添加，修改页面加载完成查询所有品牌
    public List<Brand> queryBrand(){
        return orderManageMap.queryBrand();
    }

    //根据品牌查询类型
    public List<Type> queryTypeByBrand(Brand brand){
        return orderManageMap.queryTypeByBrand(brand);
    }

    //根据类型查询型号
    public List<Product> queryModelByType(Type type){
        return orderManageMap.queryModelByType(type);
    }

    //根据商品id查商品信息
    public Product queryProductDetail(Product product){
        return orderManageMap.queryProductDetail(product);
    }

    //    插入商品明细
    public boolean detailAdd(List<OrderDetail> orderDetails){
        for (OrderDetail orderDetail : orderDetails) {
            orderDetail.setTotalprice("123123");
            Integer integer = orderManageMap.detailAdd(orderDetail);
            if (integer!=1){
                return false;
            }
        }
        return true;
    }
}
